﻿/*
 * InteractiveApp
 * 
 * objekt udrzuje informace o spustene nebo spoustejici se aplikaci
 * keeps track of single running app or app that is in 'loading' state
 * 
 * created by: asida@centrum.cz
 * 
 * initial implementation: 6.12.2011
 * last updated:
 */

//using System;
//using System.Net;
using System.ComponentModel;
//using System.Windows;
using System.Windows.Controls;
//using System.Windows.Documents;
//using System.Windows.Ink;
//using System.Windows.Input;
//using System.Windows.Media;
//using System.Windows.Media.Animation;
//using System.Windows.Shapes;
using uhul.Controls;

namespace uhul
{
  public class InteractiveApp : INotifyPropertyChanged
  {


    /// <summary>
    /// get/set <c>AppInfo</c> for current application
    /// </summary>
    public AppInfo AppInfo
    { get; set; }




    /// <summary>
    /// get/set display element that is current application GUI on screen
    /// </summary>
    public UserControl Application
    { get; set; }




    ///// <summary>
    ///// if application 
    ///// </summary>
    //public bool IsLoaded
    //{
    //  get { return !(this.Application is AppLoader); }
    //}



    private string _label;

    public string Label
    {
      get
      {
        if (_label == "" || _label == null)
          return this.AppInfo.Name;
        else
          return _label;
        }

      set
      {
        _label = value;
        this.OnPropertyChanged("Label");
      }
    }




    private bool _isActive;


    /// <summary>
    /// GUI related switch that controls application state in GUI
    /// IsActive means visible on top of user screen
    /// </summary>
    public bool IsActive
    {
      get { return _isActive; }
      set
      {
        //if (_isActive != value)
        //{
        //  XapExplorer.ChangeActiveApplication(this.AppInfo.Name);

        //}
        //this.OnPropertyChanged("IsActive");
        //_isActive = value;

        _isActive = value;

        if (value == true)
          XapExplorer.SetActiveApplication(this.AppInfo.Name);
          //XapExplorer.Commands.Add(
          //  new Command()
          //  {
          //    //CommandParameter = this.AppInfo.Name,
          //    CommandType = CommandTypeEnum.ActivateApp,
          //    TargetApplicationName = this.AppInfo.Name
          //  }.ToJson()
          //);

        this.OnPropertyChanged("IsActive");
      }
    }




    #region INotifyPropertyChanged Members

    private void OnPropertyChanged(string propName)
    {
      if (this.PropertyChanged != null)
        this.PropertyChanged(this, new PropertyChangedEventArgs(propName));
    }
    public event PropertyChangedEventHandler PropertyChanged;

    #endregion

  }


}
